/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import interfaces.GGInterface;
import interfaces.KundeInterface;
import java.rmi.RemoteException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import view.GUI;

/**
 *
 * @author Jonas
 */
public class GGClient {
    
    public static void main(String[] args) throws NamingException, RemoteException {
        
        Context namingContext = new InitialContext();

//        NameClassPair ncp;
//        Enumeration<NameClassPair> enumerator = namingContext.list("rmi://localhost/");
//        while (enumerator.hasMoreElements()) {
//            ncp = enumerator.nextElement();
//            System.out.println("\t- " + ncp.getName());
//            System.out.println("\t- " + ncp.getClassName());
//        }
        System.out.println("------------------------------");
        System.out.println("Henter objektet fjernt");
        String url = "rmi://localhost:1099/gg";
        
        GGInterface ggi = (GGInterface) namingContext.lookup(url);
        
        System.out.println("Henter kundeinfo...");
        KundeInterface kd = ggi.login(1, "1234");
        
        if (kd != null) {
            System.out.println("Loginmetoden succesfuldt!\n\t " + kd.valueToString());
        } else {
            System.out.println("Loginmetoden fejlet...");
        }
        GUI gui = new GUI();
        gui.setVisible(true);
        
        gui.setKundeNavn(kd.getName());
        gui.showVarer(kd.showVarer());
    }
}
